from strategy.StrategyTemplate import StrategyTemplate
from utils.jsl_data_map import default_columns
# from database.lhjy import engine
from strategy import strategy_filter
# from utils.simple_utls import code_fix
import pandas as pd


class Dao4(StrategyTemplate):
    """
    三低转债策略:
        三低转债策略

    """
    def __init__(self):
        super(Dao4, self).__init__()
        self.strategy_name = "低价潜在活跃债策略"
        self.strategy_descrption = "120元以下潜在活跃债"

    def run(self):
        self.data = strategy_filter.filter_base(self.data)
        self.data = self.data[self.data['现价'] < 130]
        self.data = self.data[self.data['溢价率'] < 30]
        self.data = self.data[self.data['剩余规模'] < 5]

        method = 'first'
        # pd = pd[~ pd['price_tips'].str.contains("待上市")]
        self.data['rank1'] = self.data['溢价率'].rank(method=method, ascending=True)
        self.data['rank2'] = self.data['现价'].rank(method=method, ascending=True)
        self.data['rank3'] = self.data['剩余规模'].rank(method=method, ascending=True)
        self.data['rank'] = self.data['rank1'] + self.data['rank2'] + self.data['rank3']
        self.data = self.data.sort_values(by='rank', ascending=True)

        # 获得默认列
        default_columns_extend = default_columns.copy()
        default_columns_extend.extend(['rank'])

        self.data = self.data[default_columns_extend]
        # 清掉原来的索引
        self.data.reset_index(inplace=True, drop=True)
        # print(pd)


if __name__ == '__main__':
    ins = Dao4()
    ins.topN = 20
    ins.test()